package com.example.common.base

import android.content.Context
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.View
import android.widget.LinearLayout
import androidx.appcompat.app.AlertDialog
import com.example.common.tools.TooldUtils

abstract class BaseDialog : AlertDialog {


    private var mContext: Context? = null

    constructor(context: Context) : super(context) {
        this.mContext = context
        initView()
    }


    constructor(context: Context, themeResId: Int) : super(context, themeResId) {
        this.mContext = context
        initView()
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(layout())
    }


    abstract fun initView()

    abstract fun layout(): View

    override fun show() {
        window?.setBackgroundDrawable(ColorDrawable(0))
        super.show()
    }

    fun setWidth(fraction: Int) {
        var width = TooldUtils.getScreenWidth()
        window!!.setLayout(width - (width / fraction), LinearLayout.LayoutParams.WRAP_CONTENT)
    }
}

